package com.dkm.ec.sale.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dkm.ec.sale.domain.SalePrice;
import com.dkm.ec.sale.domain.SaleSku;
import com.dkm.ec.sale.persistence.entity.SalePricePo;
import com.dkm.ec.sale.repository.SalePriceRepository;
import com.dkm.ec.sale.repository.SaleSkuRepository;
import com.dkm.ec.sale.service.SalePriceService;

@Service
public class SalePriceServiceImpl implements SalePriceService {
	
	@Resource
	private SalePriceRepository salePriceRepository;
	@Resource
	private SaleSkuRepository saleSkuRepository;

	@Override
	public synchronized void changeInventory(String soNo) {
		/*List<SoItemPo> soItemPos = soItemRepository.findSoItemBySoNo(soNo);
		if(soItemPos != null && soItemPos.size() > 0){
			for(SoItemPo soItemPo : soItemPos){
				SalePricePo salePricePo = salePriceRepository.getByProdSkuType(soItemPo.getProdSkuId(), "rush");
				if(salePricePo != null){
					Integer saleTotal = salePricePo.getSaleTotal() + soItemPo.getCount();
					salePricePo.setSaleTotal(saleTotal);
					SalePrice salePrice = salePriceRepository.newInstance(salePricePo);
					salePrice.update();
					
					if(salePricePo.getMaxTotal() - saleTotal <= 0){
						SaleSku saleSku = saleSkuRepository.load(soItemPo.getProdSkuId());
						saleSku.getData().setStatus("sold_out");
						saleSku.update();
					}
				}
			}
		}*/
	}

}
